// 函数节流
export function _throttle (fn, interval = 500) {
  let canRun = true
  return function () {
    if (!canRun) return
    canRun = false
    window.setTimeout(() => {
      canRun = true
      fn.apply(this, arguments)
    }, interval)
  }
}

// 函数防抖
export function _debounce (fn, interval = 500) {
  let time = null
  return function () {
    window.clearTimeout(time)
    time = window.setTimeout(() => {
      fn.apply(this, arguments)
      // fn()
    }, interval)
  }
}

// 处理axios传参
export const axiosParams = function (data) {
  let params = new window.URLSearchParams()
  for (let key in data) {
    params.append(key, data[key])
  }
  return params
}

// 默认规则
export const ERR_OK = 0
export const ERR_AUTH = 401
